﻿using MaterialDesignThemes.Wpf;
using Prism.Commands;
using StarryEdge.Core.Manager;
using StarryEdge.Core.Models;
using StarryEdge.Menu.SettingSystem.ViewModels.Dialog;
using StarryEdge.Menu.SettingSystem.Views.Dialog;
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Controls;

namespace StarryEdge.Menu.SettingSystem.ViewModels
{
    public class PluginSettingViewModel
    {
        public ObservableCollection<PluginInfoModel> PluginInfos { get; set; }
        private IPluginManager _pluginManager;
        public PluginSettingViewModel(IPluginManager pluginManager)
        {
            _pluginManager = pluginManager;
            PluginInfos = new ObservableCollection<PluginInfoModel>(_pluginManager.GetPluginInfos());
        }

        public DelegateCommand<ListView> Backspace => new DelegateCommand<ListView>(sender =>
        {
            if (sender.SelectedItems.Count == 0)
            {
                return;
            }
            if (DialogHost.IsDialogOpen("Global")) DialogHost.Close("Global");
            DialogHost.Show(new PluginHistoryDialog()
            {
                DataContext = new PluginHistoryPopupDialog((sender.SelectedItem as PluginInfoModel).DllName)
            }, "Global");
        });
    }
}
